home *** CD-ROM | disk | FTP | other *** search
- -- make sure the table is loaded once
- if (not MapCycle) then
- MapCycle =
- {
- iCurrentMap = 0,
- iNextMap = 1,
- };
- end
-
- -- load the map cycle from a plain text file
- -- each line is one map
- -- maps can be repeated
- -- maps are played in the order specified in the file
- function MapCycle:LoadFromFile(szFilename)
- self.MapList = {};
- self.iCurrentMap = 0;
- self.iNextMap = 1;
-
- local Lines = ReadTableFromFile(szFilename, 1);
- if (Lines) then
-
- local iSpace;
- local szMapName;
- local szGameType;
-
- for i, szLine in Lines do
- if (strlen(szLine) > 0) then
- iSpace = strfind(szLine, " ", 1, 1);
-
- if (iSpace) then
- szMapName = strsub(szLine, 1, iSpace-1);
- szGameType = strsub(szLine, iSpace+1, -1);
- else
- szMapName = szLine;
- end
-
- local Map = {};
-
- Map.szName = szMapName;
- Map.szGameType = szGameType;
-
- tinsert(self.MapList, Map);
- end
- end
-
- self.MapList.n = nil;
- end
- end
-
- -- call this everytime map changed
- function MapCycle:OnMapChanged()
-
- if (not self:IsOk()) then
- return
- end
-
- if (strlower(getglobal("g_LevelName")) ~= strlower(self.MapList[self.iNextMap].szName)) then
- return;
- end
-
- self.iCurrentMap = self.iNextMap;
- self.iNextMap = self.iCurrentMap + 1;
-
- if (self.MapList[self.iNextMap] == nil) then
- self.iNextMap = 1;
- end
-
- setglobal("gr_NextMap", self.MapList[self.iNextMap].szName);
- end
-
- -- call this to know if a map cycling is possible or no
- function MapCycle:IsOk()
- if (self.MapList and (count(self.MapList) > 0)) then
- return 1;
- end
-
- return nil;
- end
-
- -- call this to know if the scores are being shown, as a result of map finished
- function MapCycle:IsShowingScores()
- if (self.fFinishedTimer) then
- return 1;
- end
-
- return nil;
- end
-
- -- call this when the map is finished
- -- this function should load nextmap, and update self
- function MapCycle:OnMapFinished()
- -- print game statistics into console and log
- MPStatistics:Print();
- MPStatistics:Init();
- --
- printf("\002START MAPCYCLE TIMER: %g", _time);
- GameRules:ForceScoreBoard(1);
- self.fFinishedTimer = _time + 5;
- end
-
- -- call this function every frame
- -- prolly from GameRules:OnUpdate()
- function MapCycle:Update()
- if (self.fFinishedTimer and (_time > self.fFinishedTimer)) then
-
- printf("\002END MAPCYCLE TIMER: %g", _time);
-
- self.fFinishedTimer = nil;
-
- if (not self:IsOk()) then
- self.fRestartTimer = _time + 5;
-
- return
- end
-
- local Map = self.MapList[self.iNextMap];
-
- if (Map) then
- GameRules:ChangeMap(Map.szName, Map.szGameType);
- end
- elseif (self.fRestartTimer) then
- if (_time > self.fRestartTimer) then
- self.fRestartTimer = nil;
- self.fRestartTimerSecond = nil;
-
- if tostring(getglobal("gr_PrewarOn"))~="0" then
- self:NewGameState(CGS_PREWAR);
- else
- GameRules:DoRestart();
- end
- else
- local fSecond = max(0, floor(self.fRestartTimer - _time));
-
- if (fSecond ~= self.fRestartTimerSecond and fSecond > 0) then
- self.fRestartTimerSecond = fSecond;
-
- Server:BroadcastText("@GameRestartingIn "..fSecond, 0.9);
- end
- end
- end
- end
-
- -----------------------------------------------------------------------------------
- -----------------------------------------------------------------------------------
-
- -- load the map cycle file
- if (getglobal("sv_mapcyclefile")) then
- MapCycle:LoadFromFile(getglobal("sv_mapcyclefile"));
- end